<?php
/**
 * Created by PhpStorm.
 * User: xckj
 * Date: 2019/4/9
 * Time: 17:02
 */
use yii\helpers\Url;
$path = Url::to(["search/change"]);
$js = <<<Js
$(document).ready(function(){
        $(".check").click(function(){
            $.post("{$path}",$("form").serialize(),function(res){
                if(res.status == 200 && res.is_wx == 1){
                    var str = "复制这条信息，"+res.data.code+"，打开【手机淘宝】即可领券下单购买";
                    layer.confirm(str, {
                        btn: ['复制链接','拒绝复制'] //按钮
                    }, function(){
                        var btn = $("#js_copy_do");
                        btn.attr("data-copy",str);
                        btn.click();
                    }, function(){

                    });
                }else if(res.status == 200){
                    window.location.href = res.data.url;
                }else {
                    layer.msg(res.data);
                }
            },'json');
        });
    })
Js;

$this->registerJs($js);
?>
<form>
    <div class="form-group">
        <label for="exampleInputEmail1">商品链接</label>
        <input type="url" name="url" class="form-control" id="exampleInputEmail1" placeholder="商品链接">
    </div>
    <button type="button" class="btn btn-default check">查询优惠券</button>
</form>
